using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter07
{
	/// <summary>
	/// Example04: Calculating Total Work Done from a Graph
	/// A force acting on a particle varies with x, as show in 
	/// Figure 7.8. Calculate the work done by the force as 
	/// the particle moves from x=0 to x=6.0 m.
	/// W = 25 J
	/// </summary>
	public class Example04
	{
		public Example04()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Vector.FunctionOfPosition func
				= new L.Vector.FunctionOfPosition(FvsX);
			L.Force f = new L.Force();
            f.VectorFunctionOfPosition = func;
			L.Line.Parameterization pf 
				= new L.Line.Parameterization(XvsT);
			L.Line p = new L.Line(pf);
			p.ParameterStartValue = 0.0;
			p.ParameterEndValue = 6.0;
			L.Work w = new L.Work(f,p);
			result = Convert.ToString(w.J);
		}
		private L.Vector FvsX(L.Position x)
		{
			L.Vector force = new L.Vector();
			if(x.X  >= 0.0 & x.X <= 4.0) force.X = 5.0;
			else if(x.X >= 4.0 & x.X <= 6.0) force.X = 15.0 - 10.0/4.0*x.X;
			else force.X = 0.0;
			return force;
		}
		private L.Position XvsT(double t)
		{
			L.Position x = new L.Position();
			x.X = t;
			return x;
		}
	}
}
